﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Newtonsoft.Json;

public partial class Cs_HourRep : System.Web.UI.Page
{
    BLL.BLLRep br = new BLL.BLLRep();
    public static string pName = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        bool isTrue = true;
        string name = HttpUtility.UrlDecode(Request.QueryString["name"]);
        if (name != null & name != "")
        {
            pName = name;
        }

        string param = Request["param"];
        if (param != "")
        {
            if (param == "query")
            {
                string time = Request["time"];
                if (Convert.ToDateTime(time).Year == DateTime.Now.Year && Convert.ToDateTime(time).Month == DateTime.Now.Month && Convert.ToDateTime(time).Day == DateTime.Now.Day)
                    time = time + " " + (DateTime.Now.Hour + 1) + ":00:00";
                else
                    isTrue = false;
                int unit = Convert.ToInt32(Request["unit"]);

                QueryTableList(pName, unit, time, isTrue);
            }
        }
        else
        {
            QueryTableList(pName, 1, DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 0:00:00"), true);
        }
    }
    protected void QueryTableList(string title, int unit, string time, bool isTrue)
    {
        string strApp = br.RetTableByDayInfo(title, unit, Convert.ToDateTime(time));
        int count = 0;
        int index = strApp.IndexOf(',');
        int length = Convert.ToInt32(strApp.Substring(0, index));
        strApp = strApp.Remove(0, index + 1);

        if (isTrue)
            count = Convert.ToDateTime(time).Hour + 27;
        else
            count = 27;
        object obj = new
        {
            title = title,
            count = count,
            num = length,
            tableInfo = strApp
        };
        string result = JavaScriptConvert.SerializeObject(obj);
        Response.Write(result);
        Response.End();
    }

    /// <summary>   
    /// Json特符字符过滤 20110902
    /// </summary>  
    /// <param name="sourceStr">要过滤的源字符串</param>  
    /// <returns>返回过滤的字符串</returns>  
    public static string JsonCharFilter(string sourceStr)
    {
        sourceStr = sourceStr.Replace("\\", "\\\\");
        sourceStr = sourceStr.Replace("\b", "\\\b");
        sourceStr = sourceStr.Replace("\t", "\\\t");
        sourceStr = sourceStr.Replace("\n", "\\\n");
        sourceStr = sourceStr.Replace("\n", "\\\n");
        sourceStr = sourceStr.Replace("\f", "\\\f");
        sourceStr = sourceStr.Replace("\r", "\\\r");
        sourceStr = sourceStr.Replace("'", "\\'");
        return sourceStr.Replace("\"", "\\\"");
    }
}